layui.use(['jquery', 'element', 'layer', 'form', 'layedit'], function(){
    var $ = layui.$;
    var layedit = layui.layedit;
    var form = layui.form;
    var ctxPath = "/education";

    /**
     * 详情富文本
     */
    var detailEditId = layedit.build('detail', {
        height: 500,
        uploadImage :  {
            url: ctxPath + '/file/uploadPic',
            type: 'post',
        }
    });

    /**
     * 初始化积分商品详情方法
     * @param id
     */
    var initPointRewardProduct = function(id) {
        $.ajax({
            url: ctxPath + '/api/pointRewardProduct/detail',
            type: 'post',
            dataType: 'json',
            data: {pointRewardProductId: id},
            success: function (result) {
                if(result.code == 0) {
                    var data = result.data;

                    if (data != null) {
                        $("input[name='id']").val(data.id);
                        $("input[name='name']").val(data.name);
                        $("input[name='code']").val(data.code);
                        $("#previewImg").attr("src", data.showImage);
                        $("input[name='showImage']").val(data.showImage);
                        $("input[name='price']").val(data.price);
                        $("input[name='amount']").val(data.amount);

                        layedit.setContent(detailEditId, data.detail);

                        //渲染select
                        form.render('select');
                    }
                } else {
                    layer.alert("get data fail：" + result.msg);
                }
            }
        });
    }

    /**
     * 初始化积分商品
     * @type {string}
     */
    initPointRewardProduct(window.location.search.substring(4));

});

